const db = require("../db/util")

exports.selectFilms = function (typeId,pageNum=1,pageSize=6) {
    let sql = `
        select
            f.sortId , f.filmId , f.filmName , f.filmImg , avg(fc.userSource) source
        from
            film f
        left join
            film_comment fc
        on
            f.filmId = fc.filmId
        where 1=1
    `;
    if(typeId){
        sql += ` and typeId = '${typeId}'`
    }
    sql += ` group by f.filmId order by f.sortId limit ${(pageNum - 1) * pageSize},${pageSize} `
    let stmt = db.prepare(sql);
    return stmt.all();
}